package com.movitech.mobile.cz.base.supplier.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.plugins.Page;
import com.movitech.mobile.cz.base.common.aop.ServiceThrowable;
import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;
import com.movitech.mobile.cz.base.supplier.bizvo.SupplierManualListRequestVO;
import com.movitech.mobile.cz.base.supplier.entity.SSupplierManual;
import com.movitech.mobile.cz.base.supplier.service.SSupplierManualService;
import com.movitech.mobile.cz.base.syndata.SynDataService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
/**
 * <p>
 * SSupplierManual 前端控制器
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-05-11
 */
@RestController
@RequestMapping("/v1/sSupplierManual")
@Api(value = "非三个五供应商基础操作接口", description = "非三个五供应商基础操作接口")
public class SSupplierManualController {
    @Autowired
    private SSupplierManualService sSupplierManualService;
    @Autowired
    private SynDataService synDataService;

    @GetMapping("/allList")
    @ApiOperation(
            value = "获取所有非三个五供应商接口",
            notes = "获取所有非三个五供应商接口",
            response = SSupplierManual.class
    )
    public RestReturnResult list() {
    	RestReturnResult restResult = RestReturnResult.success();
        Page<SSupplierManual> page = sSupplierManualService.selectPage(new Page<SSupplierManual>());
        restResult.setData(page);
        return restResult;
    }

    @PostMapping("/searchList/{pageNumber}")
    @ApiOperation(
            value = "非三个五供应商列表查询接口",
            notes = "非三个五供应商列表查询接口",
            response = SSupplierManual.class
    )
    public RestReturnResult searchList(@RequestBody SSupplierManual sSupplierManual,
                @ApiParam(value = "分页页数")@PathVariable Integer pageNumber) {
    	RestReturnResult restResult = RestReturnResult.success();
        Page<SSupplierManual> page = new Page<>();
        page.setCurrent(pageNumber);
        EntityWrapper wrapper = new EntityWrapper<>();
        wrapper.setEntity(sSupplierManual);
        page = sSupplierManualService.selectPage(page,wrapper);
        restResult.setData(page);
        return restResult;
    }

    @GetMapping("/getSSupplierManual/{id}")
    @ApiOperation(
            value = "非三个五供应商对象ID获取接口",
            notes = "非三个五供应商对对象ID获取接口",
            response = SSupplierManual.class
    )
    public RestReturnResult addSSupplierManual(@PathVariable String id) {
    	RestReturnResult restResult = RestReturnResult.success();
        SSupplierManual sSupplierManual = sSupplierManualService.selectById(id);
        restResult.setData(sSupplierManual);
        return restResult;
    }

    @PostMapping("/add")
    @ApiOperation(
            value = "非三个五供应商添加接口",
            notes = "非三个五供应商添加接口",
            response = SSupplierManual.class
    )
    public RestReturnResult add(@RequestBody SSupplierManual sSupplierManual) {
    	RestReturnResult restResult = RestReturnResult.success();
        sSupplierManualService.insert(sSupplierManual);
        restResult.setData(sSupplierManual);
        return restResult;
    }

    @PutMapping("/update")
    @ApiOperation(
            value = "非三个五供应商更新接口",
            notes = "非三个五供应商更新接口",
            response = SSupplierManual.class
    )
    public RestReturnResult update(@RequestBody SSupplierManual sSupplierManual) {
    	RestReturnResult restResult = RestReturnResult.success();
        sSupplierManualService.updateById(sSupplierManual);
        restResult.setData(sSupplierManual);
        return restResult;
    }

    @GetMapping("/deleteSupplierManual/{id}")
    @ApiOperation(value = "非三个五供应商删除接口", notes = "非三个五供应商")
    public RestReturnResult deleteSupplierManual(@PathVariable String id) {
    	RestReturnResult restResult = RestReturnResult.success();
    	restResult = sSupplierManualService.updateSupplierManualForDel(id);
        return restResult;
    }
    
    @PostMapping("/searchSupplierManualList")
    @ApiOperation(value = "非三个五供应商列表查询接口", notes = "非三个五供应商")
    public RestReturnResult searchSupplierManualList(@RequestBody SupplierManualListRequestVO vo){
    	RestReturnResult restResult = RestReturnResult.success();
    	restResult = sSupplierManualService.searchSupplierManualList(vo);
    	return restResult;
    }
    
    
    @PostMapping("/saveOrUpdateSupplierManual")
    @ApiOperation(value = "非三个五供应商新增修改接口", notes = "非三个五供应商")
    public RestReturnResult saveOrUpdateSupplierManual(@RequestBody SSupplierManual sSupplierManual){
    	RestReturnResult restResult = RestReturnResult.success();
    	restResult = sSupplierManualService.saveOrUpdateSupplierManual(sSupplierManual);
    	return restResult;
    }

    /*
     * 统一使用：/public/checkCodeOrNumber
     * @GetMapping("/checkSupplierLicenseNo/{licenseNo}")
    @ApiOperation(value = "检测旧系统中的该供应商是否已经存在", notes = "检测旧系统中的该供应商是否已经存在")
    public RestReturnResult checkSupplierLicenseNo(@PathVariable("licenseNo") String licenseNo){
    	RestReturnResult restResult = RestReturnResult.success();
    	
    	try{
    		
    		boolean flag = synDataService.checkSupplierLicenseNo(licenseNo);
    		
    		if(flag){
    			throw new RuntimeException("该供应商已经存在", new ServiceThrowable());
    		}
    		
    	}catch(Exception e){
    		e.printStackTrace();
    		throw new RuntimeException(e.getMessage(), e.getCause());
    	}
    	
    	return restResult;
    }*/
    

}

